<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
    xmlns:dssp="http://schemas.microsoft.com/xw/2004/10/dssp.html"
    xmlns:srf08="http://www.robot-electronics.co.uk/2006/10/srf08hardware.html"
    xmlns:phys="http://schemas.microsoft.com/robotics/2006/07/physicalmodel.html"
    >

  <xsl:import href="/resources/dss/Microsoft.Dss.Runtime.Home.MasterPage.xslt" />

  <xsl:template match="/">
    <xsl:comment>
      <!-- Service Header Info -->
    </xsl:comment>
    <xsl:variable name="title">
      SRF08 Hardware Service
    </xsl:variable>
    <xsl:variable name="serviceName">
      SRF08 Hardware Service
    </xsl:variable>
    <xsl:variable name="description">
      The SRF08 is an ultrasonic ranger, with a beam width of about 30° and a maximum range of about 6m. It includes a light sensor.
    </xsl:variable>

    <xsl:call-template name="MasterPage">
      <xsl:with-param name="serviceName" select="$serviceName" />
      <xsl:with-param name="description" select="$description" />
      <!-- If title is not provided, serviceName will be used instead. -->
      <xsl:with-param name="title">
        <xsl:value-of select="$serviceName" />
        <xsl:if test="$title != ''">
          <xsl:text> - </xsl:text>
          <xsl:value-of select="$title" />
        </xsl:if>
      </xsl:with-param>
      <!-- Possible values for navigation are: 'Open', 'Closed', and 'None'
           'Open' is the default value. -->
      <xsl:with-param name="navigation" select="'Open'" />
      <!-- The contents of head param will be placed just before the </head> tag in html. -->
      <xsl:with-param name="head">
        <link rel="stylesheet" type="text/css" href="/resources/I2CHardware/Devantech.Services.I2C.Hardware.resources.DevantechI2CHardware.Stylesheet.css" />

        <style type="text/css">
          /* Service-specific stylesheet goes here */

          /*
            label { display: block; float: left; width: 100px; text-align: right; color:#666666; align: middle; margin-right: 5px; }
            fieldset { display: block; float: left; width:450px; }
          */
          label.inline { display:inline; width:20px; color:#666666; float:none; }
          input.smallInput { width: 50px; }
          input.largeInput { width: 200px; }
          input.checkbox { display:block; text-align: left; }
          input.submitButton { display: block; float: right; }
        </style>
        <script language="javascript" type="text/javascript">
          <![CDATA[<!--

/* Service-specific script goes here */

dssRuntime.init = function()
{
  // Add page initialization code here.
  // This function is attached to the window.onload event.
  // Do not override window.onload.
}

//-->     ]]>
        </script>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <!-- Match service state's document element. -->
	<xsl:template match="/srf08:SRF08HardwareState">
				<div class="RightColumn">
          
					<br/>
					<br/>
						<table class="Config">
							<tr>
								<th colspan="2">
									Broadcast Config
								</th>
							</tr>
							<tr>
								<td class="SmallText">
									Auto-Poll
								</td>
								<td class="SmallText">
									<form method="POST"  id="EnableBroadcastPollingForm">
										<input type="hidden" name="EnableBroadcastPollingChange" value="true"/>
										<input id="EnableBroadcastPolling" name="EnableBroadcastPolling" onclick="document.getElementById(this.id + 'Form').submit();"
											title="Click to enable Broadcast Polling" type="checkbox">
											<xsl:if test="srf08:EnableBroadcastPolling = 'true'">
												<xsl:attribute name="checked">CHECKED</xsl:attribute>
												<xsl:attribute name="value">on</xsl:attribute>
											</xsl:if>
										</input>
									</form>
								</td>
							</tr>

							<tr>
								<td class="SmallText">
									Delay
								</td>
								<td>
									<form method="POST"  id="BroadcastPollDelayForm">
										<input id="BroadcastPollDelay" class="Editable" maxlength="5" name="BroadcastPollDelay" onblur="this.className='Editable';document.getElementById(this.id + 'Form').submit();"
											onfocus="this.className='EditableActive'" title="Click to change the Delay between broadcast polling"
											type="text" >
											<xsl:attribute name="value">
												<xsl:value-of select="srf08:BroadcastPollDelay" />
											</xsl:attribute>
										</input>
									</form>
								</td>
							</tr>
						</table>
				</div>
        
        <br clear="all"/>
				<div class="RightColumn">
					<span class="SubTitle">
						<xsl:value-of select="count(srf08:Modules/*)" /> module<xsl:if test="count(srf08:Modules/*) &gt; 1">s</xsl:if> found
					</span>
				</div>
				<br clear="all" />
					<xsl:for-each select="srf08:Modules/*">
						<div class="Module">
							<div class="RightColumn">
								<table class="Config">
									<tr>
										<th colspan="2">
											Config
										</th>
									</tr>
									<tr>
										<td class="SmallText">
											Auto-Poll
										</td>
										<td class="SmallText">
											<form method="POST">
												<xsl:attribute name="id">EnablePolling<xsl:value-of select="srf08:I2CAddress"/>Form</xsl:attribute>
												<input type="hidden" name="EnablePollingChange" value="true"/>
												<input type="hidden" name="I2CAddress">
													<xsl:attribute name="value">
														<xsl:value-of select="srf08:I2CAddress"/>
													</xsl:attribute>
												</input>
												<input name="EnablePolling" onclick="document.getElementById(this.id + 'Form').submit();"
													title="Click to enable Polling of the sensor" type="checkbox">
													<xsl:attribute name="id">EnablePolling<xsl:value-of select="srf08:I2CAddress"/></xsl:attribute>
													<xsl:if test="srf08:EnablePolling = 'true'">
														<xsl:attribute name="checked">CHECKED</xsl:attribute>
														<xsl:attribute name="value">on</xsl:attribute>
													</xsl:if>
												</input>
											</form>
										</td>
									</tr>

									<tr>
										<td class="SmallText">
											Delay
										</td>
										<td>
											<form method="POST" >
												<xsl:attribute name="id">PollDelay<xsl:value-of select="srf08:I2CAddress"/>Form</xsl:attribute>
												<input type="hidden" name="I2CAddress">
													<xsl:attribute name="value">
														<xsl:value-of select="srf08:I2CAddress"/>
													</xsl:attribute>
												</input>
												<input  class="Editable" maxlength="5" name="PollDelay" onblur="this.className='Editable';document.getElementById(this.id + 'Form').submit();"
													onfocus="this.className='EditableActive'" title="Click to change the Delay between panning or polling"
													type="text" >
													<xsl:attribute name="id">PollDelay<xsl:value-of select="srf08:I2CAddress"/></xsl:attribute>
													<xsl:attribute name="value">
														<xsl:value-of select="srf08:PollDelay" />
													</xsl:attribute>
												</input>
											</form>
										</td>
									</tr>
								</table>
							</div>

							<span class="ModuleName">
								SRF08 found at I2C Address <xsl:choose>
									<xsl:when test="count(//srf08:Modules/*) = 1">
										<form method="POST" id="NewI2CAddressForm">
											<input id="NewI2CAddress"  name="NewI2CAddress"
											class="Editable" maxlength="3" onblur="this.className='Editable';document.getElementById(this.id + 'Form').submit();"
											onfocus="this.className='EditableActive'" title="Click to Edit the I2C Address. NB: Make sure panning and polling are off!">
												<xsl:attribute name="value">
													<xsl:value-of select="srf08:I2CAddress"/>
												</xsl:attribute>
											</input>
										</form>
										</xsl:when>
										<xsl:otherwise>
											<xsl:value-of select="srf08:I2CAddress"/>
										</xsl:otherwise>
									</xsl:choose>
							</span>
							<br/>

          

              <span class="SmallText">
								Last contact: <xsl:value-of select="srf08:Timestamp"/>
							</span>
							<br/>
              <br/>

              <span class="key">
                Light:
              </span>
              <span class="value">
                <xsl:value-of select="srf08:Light"/>
              </span>
              <br/>

              <span class="key">
                Range:
              </span>
              <span class="value">
                <xsl:value-of select="srf08:Range"/> cm
              </span>
              <br/>
              <br/>

              <form method="POST" >
                <input type="hidden" name="I2CAddress">
                  <xsl:attribute name="value">
                    <xsl:value-of select="srf08:I2CAddress"/>
                  </xsl:attribute>
                </input>
                
                <fieldset>
                  <legend>Set Sonar Properties</legend>
                  <br/>
                  <div>
                    <label for="FriendlyName">Friendly Name:</label>
                    <span>
                      <input type="text" name="FriendlyName" class="largeInput">
                        <xsl:attribute name="value">
                          <xsl:value-of select="srf08:FriendlyName"/>
                        </xsl:attribute>
                      </input>
                    </span>
                  </div>
                              
                  <div>
                    <label for="MaxDistance">Max Distance:</label>
                    <span>
                      <input type="text" name="MaxDistance" class="largeInput">
                        <xsl:attribute name="value">
                          <xsl:value-of select="srf08:MaxDistance"/>
                        </xsl:attribute> (meters)
                      </input>
                    </span>
                  </div>
                  <div>
                    <label for="AngularRange">Angular Range:</label>
                    <span>
                      <input type="text" name="AngularRange" class="largeInput">
                        <xsl:attribute name="value">
                          <xsl:value-of select="srf08:AngularRange"/>
                        </xsl:attribute>
                      </input> (degrees)
                    </span>
                  </div>
                  <div>
                    <label for="AngularResolution">Angular Resolution:</label>
                    <span>
                      <input type="text" name="AngularResolution" class="largeInput">
                        <xsl:attribute name="value">
                          <xsl:value-of select="srf08:AngularResolution"/>
                        </xsl:attribute>
                      </input> (degrees) 
                    </span>
                  </div>
                  <div>
                    <label for="PositionX">Position X:</label>
                    <span>
                      <input type="text" name="PositionX" class="smallInput">
                        <xsl:attribute name="value">
                          <xsl:value-of select="srf08:Pose/phys:Position/phys:X"/>
                        </xsl:attribute>
                      </input>
                    </span>

                    <label for="PositionY" class="inline">Y:</label>
                    <span>
                      <input type="text" name="PositionY" class="smallInput">
                        <xsl:attribute name="value">
                          <xsl:value-of select="srf08:Pose/phys:Position/phys:Y"/>
                        </xsl:attribute>
                      </input>
                    </span>

                    <label for="PositionZ" class="inline">Z:</label>
                    <span>
                      <input type="text" name="PositionZ"  class="smallInput">
                        <xsl:attribute name="value">
                          <xsl:value-of select="srf08:Pose/phys:Position/phys:Z"/>
                        </xsl:attribute>
                      </input> (meters)
                    </span>
                  </div>
                  <div>
                    <label for="OrientationX" title="X,Y,Z represent the axis and W is the rotation in radians">Orientation X:</label>
                    <span>
                      <input type="text" name="OrientationX"  class="smallInput">
                        <xsl:attribute name="value">
                          <xsl:value-of select="srf08:Pose/phys:Orientation/phys:X"/>
                        </xsl:attribute>
                      </input>
                    </span>

                    <label for="OrientationY" class="inline">Y:</label>
                    <span>
                      <input type="text" name="OrientationY" class="smallInput">
                        <xsl:attribute name="value">
                          <xsl:value-of select="srf08:Pose/phys:Orientation/phys:Y"/>
                        </xsl:attribute>
                      </input>
                    </span>
                  
                    <label for="OrientationZ" class="inline">Z:</label>
                    <span>
                      <input type="text" name="OrientationZ" class="smallInput">
                        <xsl:attribute name="value">
                          <xsl:value-of select="srf08:Pose/phys:Orientation/phys:Z"/>
                        </xsl:attribute>
                      </input>
                    </span>
                    
                    <label for="OrientationW" class="inline" title="The rotation in radians">W:</label>
                    <span>
                      <input type="text" name="OrientationW"  class="smallInput">
                        <xsl:attribute name="value">
                          <xsl:value-of select="srf08:Pose/phys:Orientation/phys:W"/>
                        </xsl:attribute>
                      </input>
                    </span>
                  </div>
                  <br/>
                  <input type="submit" value="Save" class="OrangeButton" />
                </fieldset>
              </form>
              <br clear="all"/><br/>
            
						</div>
				</xsl:for-each>
				<div class="hr"></div>
				<div class="RightColumn">
					<a class="LinkSmall" href="http://www.robot-electronics.co.uk/htm/srf08tech.shtml" target="_new">View Devantech Documentation</a>
				</div>
        Config at: /store/Devantech.Services.SRF08.Hardware.xml
	</xsl:template>
</xsl:stylesheet>
